﻿@{
    Layout = "~/Views/Shared/_Form.cshtml";
}
@model Raffles.OA.Data.Role
<style>
    .table th,
    .table td {
        text-align: center;
    }

    .table td:nth-child(odd) {
        background-color: #D9EDF7
    }
</style>
<link href="~/Content/plugin/zTree/v3/css/metroStyle/metroStyle.min.css" rel="stylesheet" />
<script src="~/Content/plugin/ztree/v3/js/ztree.min.js"></script>
<form class="form-horizontal m" role="form" onsubmit="return false;">
    <div class="panel-body table-responsive no-padding">
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>角色名称</td>
                    <td>
                        <span class="label label-success">@Model.Name</span>
                    </td>
                </tr>
                <tr>
                    <td>角色权限</td>
                    <td>
                        <div id="menuTree" class="ztree"></div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</form> 
<script>
    var roleId = frame.request("roleId");
    $(function () {
        loadMenuTree();
        if (@Model.Menus.Count > 0) {
            $('#menuTree').frameTree("setCheckedNodes", '@string.Join(",",Model.Menus.Select(x=>x.Id))');
        }
    });
    function loadMenuTree() {
        $('#menuTree').frameTree({
            async: false,
            url: '@Url.Content("/Manage/Role/LoadMenuTree")',
            check: { enable: true },
            maxHeight: "260px"
        })
    }
    function saveForm() {
        var menuIds = $('#menuTree').frameTree("getCheckedNodes");
        if (menuIds.length == 0) {
            frame.msgWarning("请勾选菜单权限");
            return;
        }
        frame.ajax({
            url: '@Url.Content("/Manage/Role/SaveMenus")',
            type: "post",
            data: { roleId, menuIds },
            success: function (obj) {
                if (obj.success) {
                    frame.msgSuccess(obj.message);
                    frame.closeDialog();
                }
                else {
                    frame.msgError(obj.message);
                }
            }
        });
    }
</script>